export const formatSize = (bytes) => {
  if (!bytes) return "";
  const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
  if (bytes === 0) return "0 Byte";
  const i = Math.floor(Math.log(bytes) / Math.log(1024));
  return `${parseFloat((bytes / Math.pow(1024, i)).toFixed(2))} ${sizes[i]}`;
};


//文件数组分类
export const classifyFile = (fileList = []) => {
    const categorizedFiles = fileList.reduce(
      (acc, curr) => {
        // 根据 editUserId 是否为 0 进行分类
        const category = curr.editUserId == 0 ? "userSubmitted" : "editorReturned";
  
        // 根据 createTime 是否相同进行进一步的分类
        const existingItem = acc[category].find(
          (item) => item.createTime === curr.createTime
        );
        if (existingItem) {
          existingItem.files.push(curr);
        } else {
          // 创建新的分类项，并按 createTime 排序
          const newItem = { createTime: curr.createTime, files: [curr] };
          acc[category].push(newItem);
          acc[category].sort((a, b) => a.createTime - b.createTime); // 按 createTime 排序
        }
  
        return acc;
      },
      { userSubmitted: [], editorReturned: [] }
    );
    return categorizedFiles;
  };